import os

# 修改文件名
def rename_files(dir_path, preExt=None):
    file_list = os.listdir(dir_path)
    for file_name in file_list:
        if preExt:
          new_name = preExt + file_name
          os.rename(os.path.join(dir_path, file_name), os.path.join(dir_path, new_name))
        # if file_name.startswith(old_name):
        #     new_file_name = file_name.replace(old_name, new_name)
        #     os.rename(os.path.join(dir_path, file_name), os.path.join(dir_path, new_file_name))

def move_files(dir_path, old_name, new_name):
    file_list = os.listdir(dir_path)
    for file_name in file_list:
        if file_name.startswith(old_name):
            new_file_name = file_name.replace(old_name, new_name)
            shutil.move(os.path.join(dir_path, file_name), os.path.join(dir_path, new_file_name))

if __name__ == '__main__':
  rename_files('../dataset/Concrete Crack Images for Classification/train/positive', preExt='positive_')